package com.zd.wechatPlatform.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.wechatPlatform.bean.model.WxFeebackMsg;
import com.zd.wechatPlatform.bean.model.WxSubscribeMsg;
import com.zd.wechatPlatform.common.enums.StatusEnum;
import com.zd.wechatPlatform.dao.WxFeebackMsgDao;
import com.zd.wechatPlatform.dao.WxSubscribeMsgDao;
import com.zd.wechatPlatform.dao.common.BaseDao;
import com.zd.wechatPlatform.dao.common.FindRequestEntity;
import com.zd.wechatPlatform.dao.common.OrderEnum;
import com.zd.wechatPlatform.dao.common.WhereEnum;
import com.zd.wechatPlatform.service.IWxSubscribeMsgService;

@Service
public class WxSubscribeMsgServiceImpl extends BaseServiceImpl<WxSubscribeMsg> implements IWxSubscribeMsgService {
	@Autowired
	private WxSubscribeMsgDao wxSubscribeMsgDao;

	@Autowired
	private WxFeebackMsgDao WxFeebackMsgDao;

	@Override
	public BaseDao<WxSubscribeMsg> getBaseDao() {
		return wxSubscribeMsgDao;
	}

	@Override
	public List<WxFeebackMsg> getSubscribeMsg(Integer accountId) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("account_id", WhereEnum.EQ, accountId);
		findReq.addWhere("status", WhereEnum.EQ, StatusEnum.valid.getKey());
		
		findReq.addOrder("seq", OrderEnum.ASC);
		
		List<WxSubscribeMsg> subscribeMsgList = find(findReq);
		
		List<WxFeebackMsg> feebackMsgList = new ArrayList<>();
		if(subscribeMsgList != null && subscribeMsgList.size() > 0) {
			for(WxSubscribeMsg subscribeMsg : subscribeMsgList) {
				feebackMsgList.add(WxFeebackMsgDao.get(subscribeMsg.getFeebackMsgId()));
			}
		}
		return feebackMsgList;
	}
}
